<div class="ui basic segment">
  <h1 class="ui dividing header">
    <%= link("News", to: Routes.admin_news_item_path(@conn, :index)) %>
    &raquo;
    <%= link(NewsItem.hashid(@item), to: Routes.admin_news_item_path(@conn, :edit, @item)) %>
    &raquo; Subscriptions
    <%= link("(View Public)", to: Routes.news_item_path(@conn, :show, NewsItem.slug(@item)), class: "view") %>
  </h1>

  <div class="actions right">
  </div>
</div>

<div class="ui basic segment">
  <div class="ui horizontal statistic">
    <div class="value"><%= @item |> Subscription.subscribed_count() |> SharedHelpers.comma_separated() %></div>
    <div class="label">Subscribed</div>
  </div>
  <div class="ui horizontal statistic">
    <div class="value"><%= @item |> Subscription.unsubscribed_count() |> SharedHelpers.comma_separated() %></div>
    <div class="label">Unsubscribed</div>
  </div>
</div>

<div class="ui basic segment">
<%= if Enum.any?(@subscriptions) do %>
  <table class="ui celled striped table">
    <thead>
      <tr>
        <th>Person</th>
        <th>Context</th>
        <th>Subscribed At</th>
        <th>Unsubscribed At</th>
      </tr>
    </thead>

    <tbody>
    <%= for sub <- @subscriptions do %>
      <tr>
        <td>
          <%= link to: Routes.admin_person_path(@conn, :show, sub.person) do %>
            <%= if Changelog.Faker.name_fake?(sub.person.name) do %>
              <%= sub.person.email %>
            <% else %>
              <img class="ui avatar image" src="<%= PersonView.avatar_url(sub.person) %>">
              <%= sub.person.name %>
            <% end %>
        <% end %>
        </td>
        <td><%= sub.context |> String.replace_leading("you", "") %></td>
        <td><%= AdminHelpers.ts(sub.inserted_at) %></td>
        <td><%= AdminHelpers.ts(sub.unsubscribed_at) %></td>
      </tr>
    <% end %>
    </tbody>
  </table>

  <%= pagination_links(@conn, @page, [@item], path: &Routes.admin_news_item_subscription_path/4) %>
<% end %>
</div>
